package jdk;

import util.ProxyUtil;
import java.io.IOException;
import java.lang.reflect.Proxy;

/**
 * @author wangpp
 */
public class JdkProxyTest {
    public static void main(String[] args) throws IOException {
        SampleServiceInterfaceImpl service = new SampleServiceInterfaceImpl();

        //save proxy class to file by system properties
        //ref {sun.misc.ProxyGenerator}
//        System.getProperties().put("sun.misc.ProxyGenerator.saveGeneratedFiles", "true");

        SampleServiceInterface proxy =
                (SampleServiceInterface) Proxy.newProxyInstance(service.getClass().getClassLoader(),
                        service.getClass().getInterfaces(),
                        new SampleInvokeHandler(service));

        //save proxy class to file
        ProxyUtil.saveJDKRuntimeClassToFile(proxy, "proxy_jdk");

        //show me the proxy class
        System.out.println(proxy.getClass());
    }
}
